import CLodopFuncs from './cLodopPrintFuncs.js';
let pickingClass={
    getPickingTemp:function (option) {
        //配货单不像发货单那样拼接模板，是直接拿了html
        //在此补充配货单打印样式
        let css=`<style>
                .picking-title{
                    text-align: center;
                    margin-top: 10px; 
                    margin-bottom: 8px;
                    font-size: 36px;
                }
                .picking-buyer-ul{
                    list-style: none !important;
                    padding: 0 !important;
                    margin: 0 !important;
                    width: 100%;
                }
                li{
                    width: 33% !important;
                    display: inline !important;
                    padding: 4px 0 !important;
                    margin: 0px !important;
                }
                .picking-full-li{
                    width: 100% !important;
                }
                .picking-item-panel{
                    border-top: 2px solid #797979;
                    border-bottom: 2px solid #797979;
                    padding: 4px 0;
                    margin: 8px 0 4px;
                }
                table{
                    border-collapse: collapse;
                    border-spacing: 0 !important;
                }
                td{
                    height: 32px !important;
                }
                .hide{
                    display: none;
                }
                </style>`;
        let temp = option.html+css;
        //console.log(temp);
        return temp;
    }
};
/**
 * c-Lodop组件打印任务
 * @class CLodopPrintClass
 */

 let CLodopPrintClass = function (){
    this.printPicking= function (isPreview, currentPrinter, data, callBack) {
        try {
            let html = pickingClass.getPickingTemp(data);
            var LODOP = CLodopFuncs.getLodop(), _status;
            if ((LODOP != null) && (typeof (LODOP.VERSION) != "undefined")) {
                LODOP.PRINT_INIT("配货单打印LODOP"); //初始化
                LODOP.ADD_PRINT_HTM(0, "2%", "96%", "297mm", html); //增加超文本打印项(普通模式)
                LODOP.SET_PRINT_STYLEA(0, "TableRowThickNess", 59);
                LODOP.SET_PRINT_PAGESIZE(1, 2100, 2970, ""); //设定纸张大小

                let printerCount = LODOP.GET_PRINTER_COUNT();
                let printerId = -1;
                if (printerCount > 0) {
                    for (let i = 0; i < printerCount; i++) {
                        if (currentPrinter === LODOP.GET_PRINTER_NAME(i)) printerId = i;
                    }
                } 
                LODOP.SET_PRINTER_INDEXA(printerId || -1); //指定默认打印机
                if (isPreview === true) {
                    LODOP.PREVIEW();
                } else {
                    _status = LODOP.PRINT();
                }
                if (_status) {
                    console.log(_status);
                    callBack && callBack(100);
                }
            }else{
                //输出LODOP错误文本
                console.log(LODOP);
                callBack && callBack(LODOP);
            }
        } catch (err) {
            console.log(err);
        }
    }
};

export default CLodopPrintClass;